<template>
  <div>
    <el-drawer
      class="orderDetail"
      :visible.sync="visible"
      direction="rtl"
      :wrapper-closable="true"
      :append-to-body="true"
      :with-header="false"
    >
      <div class="title">
        <div class="title-text">换货任务单详情</div>
      </div>
      <!-- 左右布局 -->
      <div class="center">
        <!-- 左侧 -->
        <div class="left">
          <!-- 描述列表1 -->
          <div class="section-title">基本信息</div>
          <el-descriptions size="medium" :label-style="{ 'white-space': 'nowrap' }" :content-style="{ 'word-break': 'break-all' }" style="margin-top: 20px;">
            <el-descriptions-item label="单据号">{{ temp.billCode }}</el-descriptions-item>
            <el-descriptions-item label="状态">{{ formatColumnMap(billStatusMap, 'value', temp.billStatus, 'desc') }}</el-descriptions-item>
            <el-descriptions-item label="客户编号">{{ temp.csmCode }}</el-descriptions-item>
            <el-descriptions-item label="客户名称">{{ temp.csmName }}</el-descriptions-item>
            <el-descriptions-item label="联系电话" span="2">{{ temp.csmPhone }}</el-descriptions-item>
            <el-descriptions-item label="客户地址" span="3">{{ temp.csmAddress }}</el-descriptions-item>
            <el-descriptions-item label="换货原因">{{ temp.remark }}</el-descriptions-item>
            <el-descriptions-item label="换货数量">{{ temp.goodsCount }}</el-descriptions-item>
          </el-descriptions>
          <!-- 表格 -->
          <!-- <lb-table
            ref="lbTable"
            border
            highlight-current-row
            element-loading-text="加载中"
            :column="tableData.column"
            :data="tableData.data"
            :total="tableData.total"
            custom-column
            align="center"
          /> -->
        </div>
        <!-- 右侧 -->
        <div class="right">
          <div class="timeline-title">流转信息</div>
          <el-timeline v-if="flowInfoData.length>0">
            <el-timeline-item v-for="(item, index) in flowInfoData" :key="index" :timestamp="`${parseTime(item.traceTime, '{y}-{m}-{d} {h}:{i}')} ${item.contacter}`" placement="top">
              <el-card>
                <h4>{{ item.traceDesc }}</h4>
                <h4 v-if="item.other" style="white-space: pre-wrap;" v-html="item.other" />
                <h4 v-if="item.marker">{{ `备注:${item.marker}` }}</h4>
                <p>{{ `发生部门&nbsp;——&nbsp;${item.facilityName ? item.facilityName : '系统'}` }}</p>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </div>
      </div>
      <!-- 底部 -->
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false"> 关闭 </el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
  import { barterGasDetail, queryOrderFlowInfo } from '@/api'
  import { parseTime, formatColumnMap } from '@/utils'
  export default {
    name: 'OrderDetails',
    props: {
      billStatusMap: {
        type: Array,
        default: () => []
      }
    },
    data() {
      return {
        parseTime,
        formatColumnMap,
        visible: false,
        temp: {
          billCode: ''
        },
        flowInfoData: []
        // tableData: {
        //   total: 0,
        //   column: [],
        //   data: []
        // }
      }
    },
    methods: {
      async open(temp) {
        const res = await barterGasDetail({ billCode: temp.billCode })
        if (res.data) {
          this.temp = Object.assign(this.temp, res.data)
        }
        this.getFlowInfoData(temp.billCode)
        return new Promise((resolve) => {
          this.resolve = resolve
          this.visible = true
        })
      },
      async getFlowInfoData(orderCode) {
        const res = await queryOrderFlowInfo({ orderCode })
        this.flowInfoData = JSON.parse(res.data.traceList)
      }
    }
  }
</script>

<style lang="scss" scoped>
.orderDetail {
  /deep/.el-drawer {
    width: 75% !important;
  }
}
.title {
  display: flex;
  padding: 20px 20px 0 20px;
  // margin-bottom: 20px;
  .title-text {
    line-height: 25px;
  }
  .tag {
    margin: 0 10px;
  }
}
.center {
  display: flex;
  height: calc(100vh - 120px);
  padding: 0 20px;
  overflow-y: auto;
  // height: 700px;
  font-size: 14px;
  font-weight: 400;
  color: #333;
  text-align: left;
  .left {
    position: relative;
    width: 75%;
    height: 100%;
    padding-right: 40px;
    .doneImg {
      position: absolute;
      top: 80px;
      right: 80px;
      width: 61px;
      height: 61px;
      background-image: url("../../../../assets/done2.png");
      background-size: 61px 61px;
    }

    .settlement {
      font-size: 16px;
      font-weight: 700;
      color: #F54D28;
    }

    .el-table {
      margin-bottom: 20px;
    }

    .el-descriptions {
      margin-bottom: 20px;
    }

    img {
      width: 61px;
      height: 61px;
      margin-left: 80px;
      // background-image: url("../../../../assets/done2.png");
    }
  }
  .section-title {
    padding-top: 20px;
    margin-bottom: 10px;
    font-weight: 600;
    color: #38BDBD;
  }
  .right {
    height: 100%;
    padding-left: 15px;
    border-left: 1px solid #e3e3e3;
    flex: 1;
    .timeline-title {
      width: 100%;
      padding: 8px;
      margin-bottom: 10px;
      color: white;
      background-color: #38BDBD;
      border-radius: 5px;
    }
    .el-timeline {
      margin-top: 20px;
    }
  }
}
</style>
